package com.example.aop;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @Date 2022/1/27
 * @Created by Jonathan
 */
@SuppressWarnings({"rawtypes", "unchecked"}) // ---> 注意这个解决方法
public class JDKProxy {
	public static void main(String[] args) {
		UserService userService = new UserService();
		IUserService o = (IUserService) Proxy.newProxyInstance(JDKProxy.class.getClassLoader(), new Class[]{IUserService.class}, new InvocationHandler() {
			@Override
			@SuppressWarnings("all")
			public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
				System.out.println("before");
				return method.invoke(userService, args);
			}
		});
		o.register();

	}
}
